import copy, time , calendar
from _internal_utils import to_native_string
from .compat import cookielib, urlparse, urlunparse, MutableMapping
import threading

class MockRequest(object):
    def __init__(self, request):
        self._r = request
        self._new_headers = {}
        self.type = urlparse(self._r.url).scheme

    def get_type(self):
        return self.type

    def get_host(self):
        return urlparse(self._r.url).netloc

    def get_origin_req_host(self):
        return self.get_host()

    def get_full_url(self):
        if not self._r.headers.get('Host'):
            return self._r.url
        host = to_native_string(self._r.headers.get('Host'), encoding='utf-8')
        parsed = urlparse(self._r.url)
        # recontruct the url as the way we want
        return urlunparse(
            parsed.scheme, host, parsed.path, parsed.params, parsed.query, parsed.fragment
        )

    def is_unverifiable(self):
        return True

    def has_header(self, name):
        return name in self._r.headers or name in self._new_headers

    def get_header(self, name, default=None):
        return self._r.get(name, self._new_headers.get(name, default))

    def add_header(self, key ,val):
        raise NotImplementedError('should use add_unredirected_header')

    def add_unredirected_header(self, key,val):
        self._new_headers[key] = val

    def get_new_headers(self):
        return self._new_headers

    @property
    def unverifiable(self):
        return self.is_unverifiable()

    @property
    def origin_req_host(self):
        return self.get_origin_req_host()

    @property
    def host(self):
        return self.get_host()

class MockResponse(object):
    def __init__(self, headers):
        self._headers = headers

    def info(self):
        return self._headers

    def getheaders(self, name):
        return self._headers.getheaders(name)


def extract_cookies_to_jar(jar, request, response):
    pass

class RequestsCookieJar(cookielib.CookieJar, MutableMapping):

def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
    if cookiejar is None:
        cookiejar = RequestsCookieJar()
